package br.ufrn.opencopi.graph;

import java.util.ArrayList;
import java.util.List;

import br.cnpq.webflowah.beans.Operacao;
import br.cnpq.webflowah.beans.PlanoExecucao;

/**
 * This class represents a complete graph's path between InitialVertex and FinalVertex.
 * In the composition level, it represent a ExecutionPlan.
 *
 * @author fred
 *
 */
public class GraphPath {

	private List<EdgeTuple> tuples;

	private List<Operacao> plan;

	private List<Vertex> vertexs;

	public GraphPath() {
		super();
		this.vertexs = new ArrayList<Vertex>();
		this.plan = new ArrayList<Operacao>();
		this.tuples = new ArrayList<EdgeTuple>();
		
		// TODO Auto-generated constructor stub
	}

	public GraphPath(List<Operacao> plan) {
		super();
		this.plan = plan;
		this.vertexs = new ArrayList<Vertex>();
		this.tuples = new ArrayList<EdgeTuple>();
		// TODO Auto-generated constructor stub
	}

	public GraphPath(List<EdgeTuple> tuples, List<Operacao> plan) {
		super();
		this.tuples = tuples;
		this.plan = plan;
		this.vertexs = new ArrayList<Vertex>();
	}

	public List<EdgeTuple> getTuples() {
		return tuples;
	}

	public void setTuples(List<EdgeTuple> tuples) {
		this.tuples = tuples;
	}

	public void insertTuple(EdgeTuple t){
		tuples.add(t);
	}

	public void deleteTuple(EdgeTuple t){
		tuples.remove(t);
	}


	public List<Operacao> getPlan() {
		return plan;
	}

	public void setPlan(List<Operacao> plan) {
		this.plan = plan;
	}

	public boolean hasTuple(EdgeTuple t){
		EdgeTuple tuple;
		for(int i=0; i<tuples.size();i++){
			tuple = tuples.get(i);
			if((t.getVertexIn() == tuple.getVertexIn())&& (t.getVertexOut() == tuple.getVertexOut()))
				return true;
		}
		return false;
	}

	public EdgeTuple getTupleByEdgeIn(Vertex v){
		EdgeTuple tuple;
		for(int i=0; i<tuples.size();i++){
			tuple = tuples.get(i);
			if(v == tuple.getVertexIn())
				return tuple;
		}
		return null;
	}

	public EdgeTuple getTupleByEdgeOut(Vertex v){
		EdgeTuple tuple;
		for(int i=0; i<tuples.size();i++){
			tuple = tuples.get(i);
			if(v == tuple.getVertexOut())
				return tuple;
		}
		return null;
	}


	public List<Vertex> getVertexs() {
		return vertexs;
	}

	public void setVertexs(List<Vertex> vertexs) {
		this.vertexs = vertexs;
	}

	public void addVertex(Vertex vertex) {
		if(!vertexs.contains(vertex))
			vertexs.add(vertex);
	}

}
